package com.wxy.xr.dao.impl;

import com.wxy.xr.bean.Website;
import com.wxy.xr.dao.WebsiteDao;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import java.util.ArrayList;
import java.util.List;

public class WebsiteDaoImpl extends BaseDaoImpl<Website> implements WebsiteDao {

    /**
     * 添加或更新
     * @return
     */
    public boolean save(Website bean){
        Integer id=bean.getId();
        List<Object> args = new ArrayList<>();
        args.add(bean.getFooter());
        String sql;
        if(id==null || id<1){
            sql="INSERT INTO website(footer) values(?)";
        } else {
            sql="UPDATE website set footer=? where id =?";
            args.add(bean.getId());
        }
        return tpl.update(sql,args.toArray())>0;
    }

    /**
     *获取单个对象
     * @param id
     * @return
     */
    public Website get(Integer id){
        return null;
    }

    /**
     * 获取多个对象
     * @return
     */
    public List<Website> list(){
        String sql="select id, created_time, footer from website";
        return tpl.query(sql, new BeanPropertyRowMapper<>(Website.class));
    }
}
